﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RedisClientTest
{
    public class MyRedisGroup
    {
        private int _serverIndex;
        private object _syncObj = new object();
        public MyRedisServer Cluster
        {
            get;
            set;
        }
        public System.Collections.Generic.List<MyRedisServer> Servers
        {
            get;
            set;
        }
        public int ID
        {
            get;
            set;
        }
        public int ClusterID
        {
            get;
            set;
        }
        public System.Collections.Generic.List<MyRedisServer> Masters
        {
            get;
            set;
        }
        public System.Collections.Generic.List<MyRedisServer> ReadServers
        {
            get;
            set;
        }
        public MyRedisServer GetCurrentServer()
        {
            if (this.ReadServers == null || this.ReadServers.Count == 0)
            {
                return null;
            }
            MyRedisServer result;
            lock (this._syncObj)
            {
                if (this._serverIndex > this.ReadServers.Count - 1)
                {
                    this._serverIndex %= this.ReadServers.Count;
                }
                result = this.ReadServers[this._serverIndex++];
            }
            return result;
        }
    }
}
